package com.zhuss.controller.product;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhuss.bean.bo.product.line.DetailLineBo;
import com.zhuss.bean.bo.product.line.SearchLineBo;
import com.zhuss.bean.bo.product.preline.SearchPrelineSignBo;
import com.zhuss.common.BaseController;
import com.zhuss.common.ReadService;
import com.zhuss.enums.StartStopEnum;
import com.zhuss.enums.新线招募类型;
import com.zhuss.exception.DzcxException;
import com.zhuss.product.line.LineReadServiceExt;
import com.zhuss.product.preline.PrelineSignReadServiceExt;


/**
 * @description: 线路查询Controller
 * @author: zhushanshuo
 * @create: Wed Dec 30 13:08:49 CST 2020
 **/
@RestController
@RequestMapping("/line")
public class LineReadController extends BaseController {
	
	@Autowired
	@Qualifier("lineReadService")
	private ReadService<Object, Object> lineReadService;
	
	@Autowired
	@Qualifier("lineReadServiceExt")
	private LineReadServiceExt lineReadServiceExt;
	
	@Autowired
	@Qualifier("prelineSignReadServiceExt")
	private PrelineSignReadServiceExt prelineSignReadServiceExt;
	
	/**
	 * 详情
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/detail")
    public Object detail(@RequestBody DetailLineBo bo) throws DzcxException {
		
		Object result = lineReadService.detail(bo);
		return result;
    }
	
	/**
	 * 列表
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
    @RequestMapping("/list")
    public Object list(@RequestBody SearchLineBo bo) throws DzcxException {
		bo.setStatus(String.valueOf(StartStopEnum.启用.key()));
		bo.setPretype(新线招募类型.新线招募.key());
		Object result = lineReadService.list(bo);
		return result;
    }
	
	/**
	 * 我的报名
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/mySign")
	public Object mySignList(@RequestBody SearchLineBo bo) throws DzcxException {
		bo.setStatus(String.valueOf(StartStopEnum.启用.key()));
		bo.setPretype(新线招募类型.新线招募.key());
		bo.setUserId(bo.getConcurrentUserId());
		List<Long> lineIdList = prelineSignReadServiceExt.listByUser(bo);
		if (lineIdList.isEmpty()) {
			lineIdList.add(-1l);
		}
		bo.setLineIdList(lineIdList);
		Object result = list(bo);
		return result;
	}
	
}
